package gcj2013.qual;


import java.util.Arrays;
import java.util.Comparator;

import junit.framework.AssertionFailedError;

import org.korifey.ffalg.Pair;
import org.korifey.ffalg.Sorts;

import common.AbstractRunner;
import common.AbstractRunner.SIZE;

public class A extends AbstractRunner {
		
	
	@Override
	public void handleCase(int caseNumber) throws Exception {		
		//int n = scanner.nextInt();
		char[][] c = new char[4][4];
		boolean completed = true;
		for (int i=0; i<4; i++) {
			String s = scanner.nextLine(); 
			c[i] = s.toCharArray();
			if (s.contains(".")) completed = false;
		}
		if (caseNumber < ncases) scanner.nextLine();
		
		
		for (int i=0; i<4; i++) {
			int x = 3;
			for (int j=0; j<4; j++) {
				switch (c[i][j]) {
				case 'O':
					x = x&1;
					break;
				case 'X':
					x = x&2;
					break;
				case 'T':
					break;
				case '.':
					x = 0;
					break;
				default:
					throw new AssertionFailedError();					
				}				
			}
			if (x == 0) continue;
			if (x == 2) out.write("X won\n");
			if (x == 1) out.write("O won\n");
			return;			
		}
		
		for (int i=0; i<4; i++) {
			int x = 3;
			for (int j=0; j<4; j++) {
				switch (c[j][i]) {
				case 'O':
					x = x&1;
					break;
				case 'X':
					x = x&2;
					break;
				case 'T':
					break;
				case '.':
					x = 0;
					break;
				default:
					throw new AssertionFailedError();					
				}				
			}
			if (x == 0) continue;
			if (x == 2) out.write("X won\n");
			if (x == 1) out.write("O won\n");
			return;			
		}
		
		
			int x = 3;
			for (int j=0; j<4; j++) {
				switch (c[j][j]) {
				case 'O':
					x = x&1;
					break;
				case 'X':
					x = x&2;
					break;
				case 'T':
					break;
				case '.':
					x = 0;
					break;
				default:
					throw new AssertionFailedError();					
				}				
			}
			
		    if (x > 0) {
			if (x == 2) out.write("X won\n");
			if (x == 1) out.write("O won\n");
			return;			
			}
		    
			x = 3;
			for (int j=0; j<4; j++) {
				switch (c[j][3-j]) {
				case 'O':
					x = x&1;
					break;
				case 'X':
					x = x&2;
					break;
				case 'T':
					break;
				case '.':
					x = 0;
					break;
				default:
					throw new AssertionFailedError();					
				}				
			}
			
		    if (x > 0) {
			if (x == 2) out.write("X won\n");
			if (x == 1) out.write("O won\n");
			return;			
			}
		
		out.write(completed ? "Draw\n" : "Game has not completed\n");		
	}
	
	public static void main(String[] args) throws Exception {
		new A().init(SIZE.large).execute();
	}
}

